"""查看label的像素值"""
import cv2
import os
import numpy as np

def is_image_file(filename):  #
    return any(filename.endswith(extension) for extension in [".png", ".jpg", ".jpeg",".tif",".tiff"])

if __name__=="__main__":
    label_data_path = './Training Set/label/'
    label_sets = [x for x in os.listdir(label_data_path) if is_image_file(x)]

    # 参数size可以设置数组形状,不定义size时会输出标量
    num=np.random.randint(low=0,high=4999,dtype=int)

    img_path=os.path.join(label_data_path,label_sets[num])
    img=cv2.imread(img_path)
    print(img.shape) # (256, 256, 3)
    # label的灰度像素值 {0,76}或者{0}
    print(set(img.reshape(-1)))

    # 灰度就是没有色彩，RGB色彩分量全部相等
    print(set((img[:, :, 0] == img[:, :, 1]).reshape(-1)))
    print(set((img[:, :, 0] == img[:, :, 2]).reshape(-1)))